#include "ThreadPool.h"
#include <stdlib.h>
#include <time.h>
#include <iostream>
#include <memory>
#include <functional>

using std::cout;
using std::endl;
using std::unique_ptr;
using std::bind;

extern thread_local const char *tname;

class MyTask
{
public:
    void process()
    {
       ::srand(::clock()) ;
       int number = ::rand()%100;
       cout << ">>BO_ThreadPool.MyTask number = " << number 
            << ", name = " << tname << endl;
    }
};

void test()
{
    unique_ptr<MyTask> ptask(new MyTask());

    ThreadPool pool(4, 10);
    pool.start();
    int cnt = 20;
    while(cnt--)
    {
        pool.addTask(bind(&MyTask::process, ptask.get()));
        cout << "cnt = " << cnt << endl;
    }
    pool.stop();
}

int main(int argc, char *argv[])
{
    cout << "main thread begin tname = " << tname << endl;
    test();
    cout << "main thread end tname = " << tname << endl;
    return 0;
}

